<!DOCTYPE html>
<html>
<head>
    <title>图片上传</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <style type="text/css">
      body{
        margin:0px;
        padding: 0px;
      }
      .wrapper{
        text-align: center;
        margin: 0 auto;
        position: relative;
        width:100%;
        height:150px;

      }

      #tabHeads{
        background-color: #f5f5f5;
        display: block;
        text-align: left;
        height:30px;
        line-height:30px;
        border-top:1px solid #ccc;
      }

      .active{
        background-color: #fff;
      }

      #localpic,#networklink{
        text-decoration:none;
        color: #0072C6;
        display: inline-block;
        height:28px;
        line-height:28px;
        padding: 2px 8px;
        cursor: pointer;
      }

      #tabBodys div{
        height:40px;
      }

      #networklinkup{
        text-align: left;
        padding-left: 20px;
        padding-top: 20px;
      }

      #networklinkup label{
        display: inline-block;
        height:28px;
        line-height:28px;
      }

      #url{
        display: block;
        border: 1px solid #ccc;
        width:340px;
        height:28px;
        line-height:28px;
        padding: 2px 1px;

      }

      #localpicup{
        position: relative;
        text-align: center;
        padding-top: 20px;
      }

      #localpicup button{
        display: inline-block;
        position: absolute;
        left:80px;
        top:40px;
        width:220px;
        z-index: -999;
        height:28px;
      }



      #imagefileupload{
        background: none repeat scroll 0 50% transparent;
        border: 0 none;
        font-size: 18px;
        opacity: 0;
        vertical-align: middle;
        width:220px;
        margin: 3px 0px;
        cursor: hand;
        z-index:99;
        display: inline-block;
      }

    #networklinkup{
        display: none;
      }

      #loading{
        display: none;
        position: relative;
        height:28px !important;
        z-index:999;
        margin: 15px 0px;
      }

      #loading span{
        position: absolute;
        height:28px;
        line-height:28px;
        color: #333;
        top:2px;
        left:182px;
      }

      #loading img{
        position: absolute;
        top:0px;
        left:150px;
        width:auto !important;
        height:auto !important;
      }

      #localpicup img{
        width:120px;
        height:80px;
      }
    </style>
</head>
<body>
    <div class="wrapper">
        <div id="imageTab">
            <div id="tabHeads">
                <div  id="localpic" class="active" >​本地图片</div>
                <div  id="networklink" >网络链接</div>
            </div>
            <div id="tabBodys">
                <div id="localpicup" >
                     <div id="loading" ><img src="/static/image/ajax-loader.gif"><span>正在上传...</span></div>
                     <p>
                       <button id="upbutton" >上传图片</button>
                       <input type="file" id="imagefileupload" name="imagefileupload"  size="10"  />
                     </p>  
                </div>
                <div id="networklinkup" >
                    <label>图片地址</label>
                    <input type="text" plcaceholder="http://" id="url" />
                </div>  
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../internal.js"></script>
    <script type="text/javascript" src="../tangram.js"></script>
    <script type="text/javascript" src="jquery-1.6.4.js"></script>
    <script type="text/javascript" src="ajaxupload.js"></script>


    <script type="text/javascript">

             var img = null;
             var imgWidth;
             var imgHeight;
             var imgobj= new Image()

             dialog.onok=function(){
               if(imgobj){
                 editor.execCommand( "insertImage",imgobj);
               }
             }

            $("#localpic").click(function(){
              $(this).addClass("active");
               $("#networklink").removeClass("active")
               $("#localpicup").show()
                $("#networklinkup").hide()
            });

            $("#networklink").click(function(){
               $(this).addClass("active");
               $("#localpic").removeClass("active")
               $("#localpicup").hide()
               $("#networklinkup").show()
            });



            $("input[name='imagefileupload']").change(function(){
               startupload();
            });

            var button = $('#imagefileupload'), interval;
            var fileType = "pic",fileNum = "one"; 
            new AjaxUpload(button,{
                action: '/image/blog/upload/',
                name: 'imagefileupload',
                onSubmit : function(file, ext){
                    if(fileType == "pic")
                    {
                        if (ext && /^(jpg|png|jpeg|gif)$/.test(ext.toLowerCase())){
                            this.setData({
                                'info': '文件类型为图片'
                            });
                        } else {
                            alert("不支持的格式");
                            return false;               
                        }
                    }
                                
                    
                    if(fileNum == 'one')
                        this.disable();

                    $("#loading").show();
                    $("#localpicup p").hide();
                },
                onComplete: function(file, response){

                    if(response==''){
                      return;
                    }

                    $("#loading").hide();

                    var json = eval("("+response+")");

                    if(json.status){
                        console.log(json.imgurl);
                        img = $('<img/>').attr("src","/img/blog/"+json.imgurl);
                        imgobj.src="/img/blog/"+json.imgurl
                        imgobj.width=json.width
                        imgobj.height=json.height
                        img.appendTo($("#localpicup"));
                    }else{
                        this.enable();
                        $("#localpicup p").show();
                        $("<span>"+json.error+"</span>").appendTo($("#localpicup"));
                    }               
                }
            }); 


    </script>
</body>
</html>